package cn.tworice.admin.service.impl;

import cn.tworice.admin.dao.CompaniesDao;
import cn.tworice.admin.service.CompaniesService;
import cn.tworice.common.entity.Companies;
import cn.tworice.common.entity.CompaniesType;
import cn.tworice.common.entity.dto.CompaniesDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * 企业信息业务处理
 * @Author 二饭
 * @Email 1786705138@qq.com
 * @Date 2021/12/9 19:02
 */
@Service
public class CompaniesServiceImpl implements CompaniesService {

    @Autowired
    private CompaniesDao companiesDao;

    /**
     * @param page 当前页码 0开始
     * @param pageSize 页面数据大小
     * @Author 二饭
     * @Email 1786705138@qq.com
     * @Date 2021/12/9 19:15
     */
    @Override
    public List<CompaniesDto> getList(Integer page, Integer pageSize,Integer type) {
        return companiesDao.queryCompanies((page*pageSize),pageSize,type);
    }

    /**
     * 添加或编辑企业信息
     * @Author 二饭
     * @Email 1786705138@qq.com
     * @Date 2021/12/9 20:58
     */
    @Override
    public void setCompanies(Companies companies) {
        // 添加
        if (companies.getId() == null || companies.getId().isEmpty()) {
            companies.setId(UUID.randomUUID().toString().replaceAll("-",""));
            companies.setDate(System.currentTimeMillis());
            companiesDao.insertCompanies(companies);
        }else {
            // 编辑
            companiesDao.updateCompanies(companies);
        }
    }

    /**
     * 删除企业
     * @Author 二饭
     * @Email 1786705138@qq.com
     * @Date 2021/12/9 21:14
     */
    @Override
    public void delCompanies(String id) {
        companiesDao.delCompanies(id);
    }

    /**
     * 获取企业总数
     * @Author 二饭
     * @Email 1786705138@qq.com
     * @Date 2021/12/9 21:27
     */
    @Override
    public Integer getCompaniesTotal(Integer type) {
        return companiesDao.queryCompaniesTotal(type);
    }

    /**
     * 获取企业类别列表
     * @Author 二饭
     * @Email 1786705138@qq.com
     * @Date 2021/12/9 22:10
     */
    @Override
    public List<CompaniesType> getTypeList() {
        return companiesDao.queryCompaniesType();
    }
}
